<template>
  <div class="page">
    <img src="@/assets/centerLogo.webp" style="width: 100%; height: 52px" />
    <div class="header">
      <div class="kuai">
        <div></div>
      </div>
      <div class="left">
        <img src="https://yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png" alt="" />
      </div>
      <div class="right">
        <div class="user" @click="goLogin">{{ username }}</div>
        <div class="user-item">{{ usertype }}</div>
      </div>
      <div class="bottom">
        <div class="bt"><i class="icon1"></i></div>
        <div class="bb">
          <i class="icon2"></i>
          <div class="word">
            <span>pro会员</span>
            <span>立即开通<i class="icon3"></i></span>
          </div>
        </div>
      </div>
    </div>
    <div class="center">
      <p class="center-item">我的资产</p>
      <ul class="center-nav">
        <li>
          <i>￥</i><span>0</span>
          <div>余额</div>
        </li>
        <li>
          <span>0</span>
          <div>红包</div>
        </li>
        <li>
          <span>0</span>
          <div>优惠卷</div>
        </li>
        <li>
          <span>0</span>
          <div>积分</div>
        </li>
        <li>
          <span>0</span>
          <div>礼品卡</div>
        </li>
      </ul>
    </div>
    <div class="bottom">
      <van-grid :column-num="3">
        <van-grid-item icon="photo-o" text="我的订单" />
        <van-grid-item icon="photo-o" text="账号管理" />
        <van-grid-item icon="photo-o" text="我的手机号" />
        <van-grid-item icon="photo-o" text="周六一起听" />
        <van-grid-item icon="photo-o" text="售后服务" />
        <van-grid-item icon="photo-o" text="邀请返利" />
        <van-grid-item icon="photo-o" text="优先够" />
        <van-grid-item icon="photo-o" text="积分中心" />
        <van-grid-item icon="photo-o" text="会员俱乐部" />
        <van-grid-item icon="photo-o" text="地址管理" />
        <van-grid-item icon="photo-o" text="支付安全" />
        <van-grid-item icon="photo-o" text="帮助与客服" />
        <van-grid-item icon="photo-o" text="意见反馈" />
        <van-grid-item icon="photo-o" text="我的竞拍" />
      </van-grid>

      <div class="btn" @click="goOut">退出登录</div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Grid, GridItem, Badge, Dialog } from "vant";
import { mapState } from "vuex";
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(Badge);
Vue.use(Dialog);
export default {
  name: "Center",
  data() {
    return {
      username: "请登录",
      usertype: "普通用户",
    };
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    // 前往登录页
    goLogin() {
      if (this.username !== "请登录") return;
      this.$router.replace("./login");
    },
    // 退出登录
    goOut() {
      Dialog.confirm({
        title: "退出登录?",
      })
        .then(async () => {
          await this.$store.dispatch("user/logout");
          this.$router.push({ path: "/home" });
        })
        .catch(() => {
          console.log("取消退出登录");
        });
    },
    // 获取用户信息
    async getUserInfo() {
      try {
        await this.$store.dispatch("user/userInfo");
        this.username = this.nickName;
      } catch (error) {
        console.log("出错了");
      }
    },
  },
  computed: {
    ...mapState({
      nickName: (state) => state.user.nickName,
    }),
  },
};
</script>

<style lang="less" scoped>
.page {
  // width: 100%;
  background-color: #f4f4f4;
  height: 890px;

  .header {
    width: 100%;
    height: 140px;
    background-image: url(https://yanxuan.nosdn.127.net/5905098f74e04c39fa5e76ebb9ff591b.png);
    background-size: 100%;
    display: flex;
    .kuai {
      flex: 1;
      width: 20px;
      height: 26px;
    }
    .left {
      img {
        vertical-align: middle;
        width: 71px;
        height: 71px;
        border-radius: 50%;
        margin-top: 40px;
      }
    }
    .right {
      margin-top: 55px;
      margin-left: 10px;

      div {
        color: #fff;
        font-size: 20px;
      }
      .user-item {
        color: #fff;
        font-size: 16px;
        width: 100px;
      }
    }
    .bottom {
      margin-top: 50px;
      margin-left: 60px;
      .bt {
        .icon1 {
          background-image: url(./image/1.png);
          display: inline-block;
          vertical-align: middle;
          background-size: 3.21rem 2.78rem;
          width: 31px;
          height: 31px;
          margin-left: 85px;
        }
      }
      .bb {
        display: flex;
        width: 110px;
        height: 42px;
        background-color: #181615;
        color: #d8d492;
        border-radius: 20px 0 0 20px;
        margin-left: 10px;
        .icon2 {
          background-image: url(./image/1.png);
          display: inline-block;
          vertical-align: middle;
          width: 0.56rem;
          height: 0.56rem;
          background-size: 3.21rem 2.78rem;
          background-position: -0.58rem -0.66rem;
          text-align: center;
          line-height: 0.56rem;
          margin: 10px 5px 0 10px;
        }
        .word {
          display: flex;
          flex-direction: column;
          font-size: 12px;
          span {
            .icon3 {
              background-image: url(./image/1.png);
              width: 10px;
              height: 10px;
              display: inline-block;
              vertical-align: middle;
              background-size: 3.21rem 2.78rem;
            }
          }
        }
      }
    }
  }
  .center {
    width: 100%;
    height: 110px;
    background-color: #fff;
    margin-bottom: 10px;
    .center-item {
      margin-left: 0.3rem;
      border-bottom: 0.01rem solid #d9d9d9;
      text-align: left;
      line-height: 1.04rem;
      font-size: 0.28rem;
    }
    .center-nav {
      display: flex;
      width: 100%;
      justify-content: space-between;
      font-size: 0.28rem;
      li {
        flex: 1;
        text-align: center;
        span {
          margin-bottom: 0.04rem;
          font-size: 0.42rem;
          line-height: 0.48rem;
          font-weight: 700;
        }
      }
    }
  }
  .bottom {
    .btn {
      width: 100%;
      height: 48px;
      text-align: center;
      line-height: 48px;
      margin: 10px 0;
      background-color: #fff;
    }
  }
}
</style>
